/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cc.altius.web.controller;

import cc.altius.model.Locum;
import cc.altius.model.Zone;
import cc.altius.service.HospitalService;
import cc.altius.service.LocumService;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.support.SessionStatus;

/**
 *
 * @author sagar
 */
@Controller
public class LocumController {

    @Autowired
    private LocumService locumService;
    
    @Autowired
    private HospitalService hospitalService;
    
    @ModelAttribute("zoneList")
    List<Zone> getZoneList() {
        return this.hospitalService.getZoneList();
    }
    
    @ModelAttribute("locumList")
    List<Locum> getLocumList() {
        return this.locumService.getLocumList();
    }

    @RequestMapping(value = "/locum/addLocum.htm", method = RequestMethod.GET)
    public String showAddLocumGetPage(ModelMap modelMap) {
        Locum locum = new Locum();
        modelMap.addAttribute("locum", locum);
        return "locum/addLocum";
    }

    @RequestMapping(value = "/locum/addLocum.htm", method = RequestMethod.POST)
    public String showAddLocumPostPage(@ModelAttribute("locum") Locum locum, Errors errors, SessionStatus sessionStatus) {

        this.locumService.addLocum(locum);
        sessionStatus.setComplete();
        return "redirect:addLocum.htm?msg=Succesfully Added Locum";
    }
    
    @RequestMapping(value = "/locum/listLocum.htm", method = RequestMethod.GET)
    public String showAmbulanceListPage(ModelMap modelMap) {
        return "locum/listLocum";
    }
    
    @RequestMapping(value = "/locum/updateLocum.htm", method = RequestMethod.GET)
    public String showUdateAmbulancePage(@RequestParam(value = "locumId") int locumId, ModelMap modelMap) {
        Locum locum=this.locumService.getLocumById(locumId);
        modelMap.addAttribute("locum", locum);
        return "locum/editLocum";
    }

    @RequestMapping(value = "/locum/updateLocum.htm", method = RequestMethod.POST)
    public String onSubmitPage(@ModelAttribute("locum") Locum locum, @RequestParam(value = "locumId", required = true) int locumId,
            SessionStatus sessionStatus, HttpServletRequest request) {
        //int campaignTypeId=ServletRequestUtils.getIntParameter(request, "campaignTypeId",0);

        this.locumService.updateLocum(locum, locumId);
        return "redirect:listLocum.htm?msg=Succesfully Updated Locum";

    }
}
